export const uploadUrl = 'http://localhost:8889/home/file/upload';
// import { constRoutes } from '@/router/routes';
// 筛选菜单 [{id, title, parentId, path, children}]
export function filterAsyncRouter(asyncRouterMap) {
  return asyncRouterMap.filter((route) => {
    route.meta = {
      title: route.title || '',
      icon: route.icon || '',
    };
    if (route.path) {
      route.component = loadView(route.path);
    }
    if (route.children != null && route.children && route.children.length) {
      route.children = filterAsyncRouter(route.children);
    } else {
      delete route['children'];
      delete route['redirect'];
    }
    return true;
  });
}
// 加载路由组件
export function loadView(view) {
  if (process.env.NODE_ENV === 'development') {
    return (resolve) => require([`@/views${view}`], resolve);
  } else {
    // 使用 import 实现生产环境的路由懒加载
    return () => import(`@/views${view}`);
  }
}
// 身份证号校验
let cardReg =
  /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
export const checkCard = (rule, value, callback) => {
  if (value) {
    if (!cardReg.test(value)) {
      callback(new Error('请输入正确的身份证'));
    } else {
      callback();
    }
  } else {
    callback();
  }
};
//手机校验(必填)
export let valiPhone = function (phone, value, callback) {
  let reg =
    /^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[3-8]{1})|(18[0-9]{1})|(19[0-9]{1})|(14[5-7]{1}))+\d{8})$/;
  if (!value) {
    callback(new Error('手机号不能为空'));
  } else if (!reg.test(value)) {
    callback(new Error('手机号格式错误'));
  } else {
    callback();
  }
};
// 获取时间段
export function getTimeSlot() {
  let now = new Date(),
    hour = now.getHours();
  if (hour >= 0 && hour < 12) return '早上';
  else if (hour >= 12 && hour < 18) return '下午';
  else return '晚上';
}
